package com.loong.common.rabbitmq.producer;




import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.beans.factory.annotation.Value;

/**
 * 增加延时
 */
public class ExpirationMessagePostProcessor extends CustomMessagePostProcessor {

    private Long ttl;

    public ExpirationMessagePostProcessor(Long ttl) {
        this.ttl = ttl;
    }

    @Override
    public Message postProcessMessage(Message message) throws AmqpException {
        super.postProcessMessage(message);
        // 设置过期时间
        message.getMessageProperties().setExpiration(ttl.toString());
        return message;
    }

}
